// 1. 引入vue和vue-router
import Vue from 'vue'
import Router from 'vue-router'


// 2. 在vue中使用router
Vue.use(Router)

// 3. 创建一个router
const router = new Router ({
  mode: 'history',
  routes : [

    { path: '/login', component: () => import('@/views/login/index'), hidden: true },
    { path: '/404', component: () => import('@/views/404'), hidden: true },
    {
      path: '/' ,
      redirect:'/login'
    },
    {
      path: '/screen' ,
      name:'/screen',
      component: () => import('@/views/screen_show/index'), 
    },
    { path: '*', redirect: '/404', hidden: true }
  ]
})

// 4. 导航前置守卫与导航后置守卫
// 设置路由导航前置守卫，进入路由前的操作
router.beforeEach((to, from, next) => {
  // to: 即将前往的页面路由
  // from: 即将离开的页面路由
  // next: 必须含有，进行页面跳转
  console.log(to, from, next)
  next();
})

// 导航后置守卫，进入路由后的操作
router.afterEach(() => {
  // loadingInstance.close()
})

// 5. 将路由导出即可
export default router
